import { Component } from "@angular/core";
import {NzModalService,NzModalSubject,NzNotificationService} from "ng-zorro-antd";
import { Config } from "../../../../service/config";
import { HttpServcie } from "../../../../service/http.service";
import {ElevatorRescueBean} from "../bean/elevatorRescue.bean";


@Component({
  selector: "work-order",
  templateUrl: "work-order.html",
  styleUrls: ["work-order.scss"]
})
export class WorkOrder {

  // 定义对象
  public elevatorRescueBean:ElevatorRescueBean = new ElevatorRescueBean();
  // 定义数据对象用于界面
  public elevatorRescueData:any=[];
  // 定义报警人电话
  public alarmByPhone1:any;
  // 工单编号
  public orderNum:any;


  // 定义多选框选择事件
  public allChecked: any = false;
  // 定义多选框
  public indeterminate: any = false;
  // 定义表头名称
  public modelTitle = "新增";
  // 定义模板类型
  public modal: any = 0;
  // 定义模板服务
  public currentModal: NzModalSubject;
  //表格
  public config: any = Config;
  // 定义初始化实体类
  // 定义总条数
  public total:any;
  // 定义选中的数据
  public clickItemDate:any=[];
  // 定义点击的行数据
  public clumeData:any;


  constructor(
    private httpServcie: HttpServcie,
    private _notification: NzNotificationService,
  ) {
    JSON.parse(window.localStorage.getItem("user"));
    this.elevatorRescueBean.pageSize = 10;
    this.elevatorRescueBean.currentPage = 1;
  }

  ngOnInit() {
    /**
     * 初始化数据表格
     */
    this.queryData();
  }
  //查询
  queryData() {
    let elevatorRescueBean = new ElevatorRescueBean();
    // 报警人电话
    if(this.alarmByPhone1 !=null && this.alarmByPhone1 !=''){
      elevatorRescueBean.alarmByPhone1 = this.alarmByPhone1;
    }
    // 工单编号
    if(this.orderNum !=null && this.orderNum !=''){
      elevatorRescueBean.orderNum = this.orderNum;
    }

    elevatorRescueBean.currentPage = this.elevatorRescueBean.currentPage;
    elevatorRescueBean.pageSize = this.elevatorRescueBean.pageSize;
    this.httpServcie.initWorkOrder(elevatorRescueBean).subscribe(data => {
      if (data.status == "200") {
        console.log(data);
        if (data.data) {
          this.elevatorRescueData = data.data.list;
          this.total = data.data.total;
        } else {
          this.elevatorRescueData = [];
        }
      } else {
        this._notification.create("error", "错误提示", data.message);
      }
    });
  }

  //全选
  checkAll(value) {
    if (value) {
      this.elevatorRescueData.forEach(data => {
        if (!data.disabled) {
          data.checked = true;
        }
      });
    } else {
      this.elevatorRescueData.forEach(data => (data.checked = false));
    }
  }

  //table加载数据时
  displayDataChange($event) {
    this.elevatorRescueData = $event;
    this.refreshStatus();
  }

  //重置选择框
  refreshStatus() {
    const allChecked = this.elevatorRescueData.every(
      value => value.disabled || value.checked
    );
    const allUnChecked = this.elevatorRescueData.every(
      value => value.disabled || !value.checked
    );
    this.allChecked = allChecked;
    this.indeterminate = !allChecked && !allUnChecked;
  }


  //分页
  nzPageSizeChange(event) {
    this.elevatorRescueData.pageSize = event;
    this.elevatorRescueData.currentPage = 1;
    this.queryData();
  }

  //输入框的方法
  nzPageIndexChange(event) {
    this.elevatorRescueData.currentPage = event;
    this.queryData();
  }

  //当前页
  nzPageIndexClickChange(event) {
    this.elevatorRescueData.currentPage = event;
    this.queryData();
  }




}
